<?php

class Model_Teacher extends Model_Dec {

	const TABLE = "teacher";
	
	/**
	 * @var protected $id id value
	 * @method int get_id() get_id(void)
	 * @method void set_id() set_id(int $id)
	 */
	protected $id;
	
	/**
	 * @var protected $display_name display_name value
	 * @method string get_display_name() get_display_name(void)
	 * @method void set_display_name() set_display_name(string $display_name)
	 */
	protected $display_name;
	
	/**
	 * @var protected $university_id university_id value
	 * @method int get_university_id() get_university_id(void)
	 * @method void set_university_id() set_university_id(int $university_id)
	 */
	protected $university_id;
	
	/**
	 * @var protected $institution_id institution_id value
	 * @method int get_institution_id() get_institution_id(void)
	 * @method void set_institution_id() set_institution_id(int $institution_id)
	 */
	protected $institution_id;

	/**
	 * @return Model_Teacher
	 */
	public function __construct($id=0) {
		if(0<intval($id)) {
			$db = DB::select("*")->from(self::TABLE)->where("id", "=", $id)->limit(1);
			$db = $db->as_assoc()->execute();
			if($db->count()>0) {
				$this->load($db->current());
			}
		}
	}

	protected static function get_database_fields() {
		return array(
			'display_name' => __("Teacher_Display_name"),
			'university_id' => __("Teacher_University_id"),
			'institution_id' => __("Teacher_Institution_id"),
		);
	}

	public function validate() {
		$validateArray = array();
		foreach (self::get_database_fields() as $key => $value) {
			$validateArray[$key] = $this->get($key);
		}
		$validation = Validation::factory($validateArray)
				->rule('display_name', 'not_empty')
				;
		if ($validation->check()) {
			return $validateArray;
		} else {
			throw new Validation_Exception('validation', $validation);
		}
	}

	public static function get_report() {
		return DB::select(
				"id"
				, "display_name"
				, "university_id"
				, "institution_id"
				, array("id", "actions"))
		->from(self::TABLE)
		->order_by("id", "ASC");
	}

}